package com.lk.ii.service;


import com.lk.ii.constant.IiConstants;
import com.lk.ii.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;

@Service("ii")
public class IIService {

    @Autowired
    private IIiCategoryService categoryService;

    @Autowired
    private IIiAuthorService authorService;

    @Autowired
    private IIiArticleService articleService;

    @Autowired
    private IIiVideoService videoService;

    @Autowired
    private IIiActivityService activityService;

    @Autowired
    private IIiEncyclopediaService encyclopediaService;

    @Autowired
    private IIiProductService productService;

    @Autowired
    private IIiSolutionService solutionService;

    @Autowired
    private IIiCaseService caseService;

    @Autowired
    private IIiResearchReportService researchReportService;

    @Autowired
    private IIiRecommendService recommendService;

    @Autowired
    private IIiRecommendMaterialService recommendMaterialService;

    @Autowired
    private IIiAdService adService;

    @Autowired
    private IIiAdMaterialService adMaterialService;

    @Autowired
    private IIiMaterialService iiMaterialService;


    public IIiCategoryService getCategoryService() {
        return this.categoryService;
    }

    public IIiAuthorService getAuthorService() {
        return this.authorService;
    }

    public IIiArticleService getArticleService() {
        return this.articleService;
    }

    public IIiVideoService getVideoService() {
        return this.videoService;
    }

    public IIiActivityService getActivityService() {
        return this.activityService;
    }


    public IIiEncyclopediaService getEncyclopediaService() {
        return this.encyclopediaService;
    }

    public IIiProductService getProductService() {
        return this.productService;
    }

    public IIiSolutionService getSolutionService()
    {
        return this.solutionService;
    }

    public IIiCaseService getCaseService()
    {
        return this.caseService;
    }

    public IIiResearchReportService getResearchReportService() {
        return this.researchReportService;
    }

    public String[] getMaterialType(){
        return IiConstants.MATERIAL_TYPES;
    }

    /**
     * 根据对象类别获取分类列表
     *
     * @param type 对象类别
     * @return List<IiCategory>
     */
    public List<IiCategory> getCategoryList(String type)
    {
        IiCategory iiCategory = new IiCategory();
        iiCategory.setType(type);
        iiCategory.setStatus(1);
        return categoryService.selectIiCategoryList(iiCategory);
    }

    /**
     * 获取作者列表
     *
     * @return List<IiAuthor>
     */
    public List<IiAuthor> getAuthorList()
    {
        IiAuthor iiAuthor = new IiAuthor();
        iiAuthor.setStatus(1);
        return  authorService.selectIiAuthorList(iiAuthor);
    }


    /**
     * 获取分类文章列表
     *
     * @param categoryId
     * @param offset 偏移量
     * @return
     */
    public List<IiArticle> getCategoryArticleList(Long categoryId, Long pageSize, Long offset)
    {
        return articleService.getCategoryArticleList(categoryId, pageSize, offset);
    }

    /**
     * 获取分类视频列表
     *
     * @param categoryId 分类ID
     * @param offset 偏移量
     * @return
     */
    public List<IiVideo> getCategoryVideoList(Long categoryId, Long pageSize, Long offset)
    {
        return videoService.getCategoryVideoList(categoryId, pageSize, offset);
    }

    /**
     * 获取即将开始活动列表
     *
     * @param startTime 开始时间
     * @param offset 偏移量
     * @return
     */
    public List<IiActivity> getComingActivityList(String startTime, Long pageSize, Long offset)
    {
        return activityService.getComingActivityList(startTime, pageSize, offset);
    }

    /**
     * 获取百科列表
     *
     * @param offset 偏移量
     * @return
     */
    public List<IiEncyclopedia> getEncyclopediaList(Long pageSize, Long offset)
    {
        return encyclopediaService.getEncyclopediaPageList(pageSize, offset);
    }

    /**
     * 获取产品服务列表
     *
     * @param offset 偏移量
     * @return
     */
    public List<IiProduct> getProductList(Long pageSize, Long offset)
    {
        return productService.getProductPageList(pageSize, offset);
    }

    /**
     * 获取解决方案列表
     *
     * @param offset 偏移量
     * @return
     */
    public List<IiSolution> getSolutionList(Long pageSize, Long offset)
    {
        return solutionService.getSolutionPageList(pageSize, offset);
    }

    /**
     * 获取案例列表
     *
     * @param offset 偏移量
     * @return
     */
    public List<IiCase> getCaseList(Long pageSize, Long offset)
    {
        return caseService.getCasePageList(pageSize, offset);
    }

    /**
     * 获取研究报告列表
     *
     * @param offset 偏移量
     * @return
     */
    public List<IiResearchReport> getResearchReportList(Long pageSize, Long offset)
    {
        return researchReportService.getResearchReportPageList(pageSize, offset);
    }

    /**
     * 获取推荐文章列表
     *
     * @param code
     * @return
     */
    public List<IiArticle> getRecommendArticleList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiArticle> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiArticle article = articleService.selectIiArticleById(recommendMaterial.getObjectId());
            list.add(article);
        }
        return list;
    }

    /**
     * 获取推荐活动列表
     *
     * @param code
     * @return
     */
    public List<IiActivity> getRecommendActivityList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiActivity> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiActivity activity = activityService.selectIiActivityById(recommendMaterial.getObjectId());
            list.add(activity);
        }
        return list;
    }

    /**
     * 获取推荐视频列表
     *
     * @param code
     * @return
     */
    public List<IiVideo> getRecommendVideoList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiVideo> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiVideo video = videoService.selectIiVideoById(recommendMaterial.getObjectId());
            list.add(video);
        }
        return list;
    }

    /**
     * 获取推荐百科列表
     *
     * @param code
     * @return
     */
    public List<IiEncyclopedia> getRecommendEncyclopediaList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiEncyclopedia> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiEncyclopedia encyclopedia = encyclopediaService.selectIiEncyclopediaById(recommendMaterial.getObjectId());
            list.add(encyclopedia);
        }
        return list;
    }



    /**
     * 获取推荐产品列表
     *
     * @param code
     * @return
     */
    public List<IiProduct>  getRecommendProductList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiProduct> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiProduct product = productService.selectIiProductById(recommendMaterial.getObjectId());
            list.add(product);
        }
        return list;
    }

    /**
     * 获取推荐解决方案列表
     *
     * @param code
     * @return
     */
    public List<IiSolution>  getRecommendSolutionList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiSolution> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiSolution solution = solutionService.selectIiSolutionById(recommendMaterial.getObjectId());
            list.add(solution);
        }
        return list;
    }

    /**
     * 获取推荐案例列表
     *
     * @param code
     * @return
     */
    public List<IiCase>  getRecommendCaseList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiCase> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiCase _case = caseService.selectIiCaseById(recommendMaterial.getObjectId());
            list.add(_case);
        }
        return list;
    }

    /**
     * 获取推荐研究报告列表
     *
     * @param code
     * @return
     */
    public List<IiResearchReport>  getRecommendResearchReportList(String code)
    {
        IiRecommend iiRecommend = recommendService.selectIiRecommendByCode(code);
        List<IiRecommendMaterial> recommendMaterialList = recommendMaterialService.getIiRecommendMaterialList(iiRecommend.getId());
        List<IiResearchReport> list = new ArrayList<>();
        for (IiRecommendMaterial recommendMaterial : recommendMaterialList) {
            IiResearchReport report = researchReportService.selectIiResearchReportById(recommendMaterial.getObjectId());
            list.add(report);
        }
        return list;
    }

    /**
     * 获取广告
     *
     * @param code 编码
     * @return
     */
    public List<IiAdMaterial> getAdList(String code)
    {
        IiAd iiAd = adService.selectIiAdByCode(code);
        List<IiAdMaterial> list = adMaterialService.getIiAdMaterialList(iiAd.getId());
        for (IiAdMaterial m : list) {
            IiMaterial iiMaterial = iiMaterialService.selectIiMaterialById(m.getMaterialId());
            m.setMaterialName(iiMaterial.getName());
            m.setMaterialUrl(iiMaterial.getUrl());
        }
        return list;
    }
}
